import type { VueComType } from "./common";
// 基本属性
export interface BaseProps {
  id: string;
  isShow: boolean;
  name: string;
  editCom: VueComType;
}

export type StringStatusArr = string[]
export type ValueStatusArr = Array<{ value: string, status: string }>
export type PicTitleDescStatusArr = Array<{ picTitle: string, picDesc: string, value: string }>

// 文本属性
export interface TextProps extends BaseProps {
  status: string;
}
export type OptionsStatusArr = StringStatusArr | ValueStatusArr | PicTitleDescStatusArr
// 选项属性
export interface OptionsProps extends BaseProps {
  status: OptionsStatusArr
  currentStatus: number
}

// 公共的设置项，每个组件都有的设置项
export interface BaseStatus {
  title: TextProps;
  desc: TextProps;
  position: OptionsProps;
  titleSize: OptionsProps;
  descSize: OptionsProps;
  titleWeight: OptionsProps;
  descWeight: OptionsProps;
  titleItalic: OptionsProps;
  descItalic: OptionsProps;
  titleColor: TextProps;
  descColor: TextProps;
}
// 因为不是所有的业务组件都有options这个设置项，所以要分开定义
export interface OptionsStatus extends BaseStatus {
  options: OptionsProps;
}

export interface TypeStatus extends BaseStatus {
  type: OptionsProps
}

export function isOptionStatus(status: BaseStatus): status is OptionsStatus {
  return 'options' in status
}

export function isTypeStatus(status: BaseStatus): status is TypeStatus {
  return 'type' in status
}

// 确定status是字符串数组 
export function isStringArray(status: OptionsStatusArr): status is string[] {
  return Array.isArray(status) && status.every(item => typeof item === 'string')
}

// 确定status是{value:string,status:string}这种类型的数组
export function isValueStatusArray(status: OptionsStatusArr): status is ValueStatusArr {
  return (
    Array.isArray(status) &&
    typeof status[0] === 'object' &&
    'value' in status[0] &&
    'status' in status[0]
  )
}

// 确定status是{picTitle:string,picDesc:string,value:string}这种类型的对象
export function isPicTitleDescStatusArr(status: OptionsStatusArr): status is PicTitleDescStatusArr {
  return (
    Array.isArray(status) &&
    typeof status[0] === 'object' &&
    'picTitle' in status[0] &&
    'picDesc' in status[0] &&
    'value' in status[0]
  )
}

export type PicLink = { link: string, index: number }
export function isPicLink(obj: object): obj is PicLink {
  return 'link' in obj && 'index' in obj
}

export type GetLink = (obj: PicLink) => void

export type updateStatus = (
  configKey: string,
  payload?: number | string | boolean | PicLink,
) => void